﻿var lastLayerNode = null;//最后一次点击的图层节点
var layersInfo;
var isTransit = false;//是否中转路径;
var resourceCatalogTree = null;
//var configInfo = InitialParameter("/Config.json");// 引入ajax请求的基路径http://192.168.100.123:8887


//初始化目录树
function fillResourceCatalog() {
    var listNode = getNodeByID("div_left_content_control");
    listNode.innerHTML = "<div style='height:10px;'></div>";
    var resourceCatalogStr = getResourceCatalog();
    //var resourceCatalog = $.parseJSON(resourceCatalogStr);
    //var resourceCatalog = changeStrToJsonOrArray(resourceCatalogStr, null, true, "json");
    //resourceCatalogTree = getTreeCatalog(resourceCatalog);
    resourceCatalogTree = getTreeCatalog(JSON.parse(resourceCatalogStr).data);
    for (var key in resourceCatalogTree) {
        var div_group = createNode("div");
        div_group.className = "catalogTree";
        div_group.setAttribute("isopen", "false");
        div_group.style.height = "30px";

        var span_group = createNode("span");
        span_group.style = "position:relative;left:20px;"

        //箭头
        var i_group_arrow = createNode("i");
        i_group_arrow.className = "fa fa-caret-right";
        span_group.appendChild(i_group_arrow);
        span_group.appendChild(suojinNode(2));

        //图标
        var span_group_icon = createNode("span");
        span_group_icon.innerHTML = "&nbsp&nbsp&nbsp";
        span_group_icon.className = "group_icon";
        span_group.appendChild(span_group_icon);

        //标题
        var font_group_title = createNode("font");
        font_group_title.className = "catalogTreeTitle";
        font_group_title.innerHTML = resourceCatalogTree[key].name;
        font_group_title.title = resourceCatalogTree[key].name;
        font_group_title.style.cursor = "pointer";
        font_group_title.setAttribute("catalogAttr", resourceCatalogTree[key].name);
        font_group_title.setAttribute("catalogid", key);
        span_group.appendChild(font_group_title);
        span_group.appendChild(suojinNode(2));

        ////添加图层
        //var i_group_add = createNode("i");
        //i_group_add.title = "添加图层";
        //i_group_add.className = "fa fa-plus opraButton";
        //i_group_add.style.cursor = "pointer";
        //i_group_add.onclick = function (evt) {
        //    clickAddLayer(evt.target);
        //};
        //span_group.appendChild(i_group_add);

        ////下移
        //var i_group_down = createNode("i");
        //i_group_down.title = "下移";
        //i_group_down.className = "fa fa-arrow-circle-o-down";
        //i_group_down.style.cursor = "pointer";
        //i_group_down.style.float = "right";
        //i_group_down.style.position = "relative";
        //i_group_down.style.top = "5px";
        //i_group_down.style.right = "30px";
        //i_group_down.onclick = function (evt) {
        //    changeNodeOrderNum(evt.target.parentNode.parentNode, "down");
        //}
        //span_group.appendChild(i_group_down);

        ////上移
        //var i_group_up = createNode("i");
        //i_group_up.title = "上移";
        //i_group_up.className = "fa fa-arrow-circle-o-up";
        //i_group_up.style.cursor = "pointer";
        //i_group_up.style.float = "right";
        //i_group_up.style.position = "relative";
        //i_group_up.style.top = "5px";
        //i_group_up.style.right = "40px";
        //i_group_up.onclick = function (evt) {
        //    changeNodeOrderNum(evt.target.parentNode.parentNode, "up");
        //}
        //span_group.appendChild(i_group_up);

        div_group.appendChild(span_group);
        listNode.appendChild(div_group);
    }
    
    $(".catalogTreeTitle").click(function (evt) {
        clickCatalogTreeTitle(evt.target);
    });
}
function clickCatalogTreeTitle(node) {
    var parentNode = node.parentNode.parentNode;
    var catalogAttr = node.attributes.catalogattr.value;
    var catalogid = node.attributes.catalogid.value;
    getNodeByID("span_layer_path").innerHTML = "&nbsp当前目录";
    getNodeByID("span_layer_path1").innerHTML = catalogAttr.replace(/\|/g, " >> ");
    getNodeByID("ipt_catalogattr").value = catalogAttr;
    if (parentNode.attributes.isopen.value=="true") {
        parentNode.attributes.isopen.value = "false";
        $(parentNode).next().remove();
        $(parentNode).find(".fa-caret-down")[0].className = "fa fa-caret-right";
        return;
    }
    parentNode.attributes.isopen.value = "true";
    $(parentNode).find(".fa-caret-right")[0].className = "fa fa-caret-down";
    var catalogChildNode = document.createElement("div");
    //var catalogAttrArr=catalogAttr.split("|");
    var childcatalog;
    for (var i = 0; i < catalogid.length/3; i++) {
        if (i==0) {
            childcatalog = resourceCatalogTree[catalogid.slice(0,3)].lower;
        }
        else {
            childcatalog = childcatalog[catalogid.slice(0, 3 * (i + 1))].lower;
        }
    }
    for (var key in childcatalog) {
        var div_catalogchild = createNode("div");
        div_catalogchild.className = "catalogTree";
        div_catalogchild.setAttribute("isopen", "false");
        div_catalogchild.style.height = "30px";

        var span_catalogchild = createNode("span");
        span_catalogchild.style = "position:relative;left:20px;"

        //箭头
        var i_catalogchild_arrow = createNode("i");
        i_catalogchild_arrow.className = "fa fa-caret-right";
        span_catalogchild.appendChild(suojinNode(4 * (catalogid.length/3 + 1)));
        span_catalogchild.appendChild(i_catalogchild_arrow);

        //图标
        var span_catalogchild_icon = createNode("span");
        span_catalogchild_icon.innerHTML = "&nbsp&nbsp&nbsp";
        span_catalogchild_icon.className = "catalogchild_icon";
        span_catalogchild.appendChild(span_catalogchild_icon);

        //标题
        var font_catalogchild_title = createNode("font");
        font_catalogchild_title.className = "catalogTreeTitle";
        font_catalogchild_title.onclick = function (evt) { clickCatalogTreeTitle(evt.target); }
        var font_catalogchild_title_innerHTML = childcatalog[key].name;
        if (catalogid.length / 3 + childcatalog[key].name.length > 12) {
            font_catalogchild_title_innerHTML = childcatalog[key].name.slice(0, 12 - (catalogid.length / 3)) + "...";
        }
        font_catalogchild_title.innerHTML = font_catalogchild_title_innerHTML;
        font_catalogchild_title.title = childcatalog[key].name;
        font_catalogchild_title.style.cursor = "pointer";
        font_catalogchild_title.setAttribute("catalogAttr", catalogAttr + "|" + childcatalog[key].name);
        font_catalogchild_title.setAttribute("catalogid", key);
        span_catalogchild.appendChild(font_catalogchild_title);
        span_catalogchild.appendChild(suojinNode(2));

        ////添加图层
        //var i_catalogchild_add = createNode("i");
        //i_catalogchild_add.title = "添加图层";
        //i_catalogchild_add.className = "fa fa-plus opraButton";
        //i_catalogchild_add.style.cursor = "pointer";
        //i_catalogchild_add.onclick = function (evt) {
        //    clickAddLayer(evt.target);
        //};
        //span_catalogchild.appendChild(i_catalogchild_add);

        div_catalogchild.appendChild(span_catalogchild);
        catalogChildNode.appendChild(div_catalogchild);
    }
    layersInfo = getLayersByCatalog("", catalogAttr);
    for (var key in layersInfo) {
        if (JSON.stringify(layersInfo[key]) != '{}') {
            catalogChildNode.appendChild(createLayerNode(layersInfo[key], catalogAttr));
        }
    }
    $(parentNode).after(catalogChildNode);
}
function clickAddLayer(node) {
    getNodeByID("ipt_layer_guid").value = "insert";
    openAddDiv("layer");
    var titleNode = $(node.parentNode).find(".catalogTreeTitle")[0];
    var catalogattr = titleNode.attributes.catalogattr.value;
    getNodeByID("ipt_catalogattr").value = catalogattr;
    getNodeByID("font_checked_catalogattr").innerHTML = catalogattr.replace(/\|/g, ">>");
}
//创建一个图层节点
function createLayerNode(layerInfo, catalogAttr) {
    var reg = /.*?_$/g;
    var isGroupNode = reg.exec(layerInfo.GUID);

    var catalogAttrArrlayer = catalogAttr.split("|");
    var div_catalogchild_layer = createNode("div");
    div_catalogchild_layer.className = "catalogLayer";
    div_catalogchild_layer.style.height = "30px";

    var span_catalogchild_layer = createNode("span");
    span_catalogchild_layer.style = "position:relative;left:20px;"
    var suojinNum = (catalogAttrArrlayer.length * 5) - 1;
    if (catalogAttrArrlayer.length>=4) {
        suojinNum = suojinNum - 1;
    }
    else if (catalogAttrArrlayer.length==2) {
        suojinNum = suojinNum + 1;
    }
    span_catalogchild_layer.appendChild(suojinNode(suojinNum));
    //图标
    var span_catalogchild_icon_layer = createNode("span");
    span_catalogchild_icon_layer.innerHTML = "&nbsp&nbsp&nbsp";
    if (isGroupNode) {//如果是图层组，改变图标
        span_catalogchild_icon_layer.className = "catalogchild_icon";
    }
    else {
        span_catalogchild_icon_layer.className = "cataloglayer_icon";
    }
    span_catalogchild_layer.appendChild(span_catalogchild_icon_layer);

    //标题
    var font_catalogchild_title_layer = createNode("font");
    font_catalogchild_title_layer.className = "catalogLayerTitle";
    font_catalogchild_title_layer.onclick = function (evt) { clickCatalogTreeTitle(evt.target); }
    var font_catalogchild_title_innerHTML = layerInfo.LAYERALIAS;
    if (catalogAttrArrlayer.length + layerInfo.LAYERALIAS.length > 12) {
        font_catalogchild_title_innerHTML = layerInfo.LAYERALIAS.slice(0, 12 - (catalogAttrArrlayer.length)) + "...";
    }
    font_catalogchild_title_layer.innerHTML = font_catalogchild_title_innerHTML;
    font_catalogchild_title_layer.title = layerInfo.LAYERALIAS;
    font_catalogchild_title_layer.style.cursor = "pointer";
    font_catalogchild_title_layer.setAttribute("catalogAttr", catalogAttr + "|  •§• " + layerInfo.LAYERALIAS);
    font_catalogchild_title_layer.setAttribute("layerguid", layerInfo.GUID);
    font_catalogchild_title_layer.onclick = function (evt) {
        clickLayer(evt.target);
    }
    span_catalogchild_layer.appendChild(font_catalogchild_title_layer);
    div_catalogchild_layer.appendChild(span_catalogchild_layer);
    return div_catalogchild_layer;
}
//点击图层时
function clickLayer(layerNode) {
    var layerCatalogAttr = layerNode.attributes.catalogattr.value;
    getNodeByID("span_layer_path1").innerHTML = layerCatalogAttr.replace(/\|/g, " >> ");
    var layerguid = layerNode.attributes.layerguid.value;
    var reg = /.*?_$/g;
    var isGroupNode=reg.exec(layerguid);
    if (isGroupNode) {//图层组
        if ($(layerNode).parent().parent().attr("isopen") && $(layerNode).parent().parent().attr("isopen")=="true") {
            $(layerNode).parent().parent().attr("isopen", "false");
            $(layerNode).parent().parent().next().remove();
            return;
        }
        var catalogChildNode = document.createElement("div");
        layersInfo = getLayersByLayerGroup(layerguid);
        for (var key in layersInfo) {
            if (JSON.stringify(layersInfo[key]) != '{}') {
                catalogChildNode.appendChild(createLayerNode(layersInfo[key], layerCatalogAttr));
            }
        }
        $(layerNode).parent().parent().after(catalogChildNode);
        $(layerNode).parent().parent().attr("isopen", "true");
    }
    else {//图层       
        var layerInfo = getResourceByGUID(layerguid);
        for (var key in layerInfo) {
            layerInfo = layerInfo[key];
            break;
        }
        OpenGroupOrLayerInfo("layer");
        var layerInfoNodes = document.getElementsByClassName("ipt_layer_info");
        var metaInfoNodes = document.getElementsByClassName("ipt_meta_info");
        var node = null;
        var name = null;
        var value = null;
        for (var i = 0; i < layerInfoNodes.length - metaInfoNodes.length; i++) {
            node = layerInfoNodes[i];
            name = node.name;
            value = layerInfo[name];
            //如果是服务器做特殊处理
            if (name == "RESOURCEPOSITION") {
                var childNodes = $(node).find("option");
                for (var j = 0; j < childNodes.length; j++) {
                    if ($(childNodes[j]).text()==value) {
                        value = $(childNodes[j]).val();
                    }
                }
            }
            else if (name == "POSITION") {
                value = layerInfo["LAYERPOSITION"];
            } else if (name == "SERVICESTYPE") {
                value = layerInfo["SERVICE_CATEGORY"];
            } else if (name == "COMPANY") {
                var portaluserno = getUser();
                var strCompanyData = null;
                strCompanyData = getCompanyDataDict(portaluserno);
                value = strCompanyData.fkDept;
            }
            //将属性赋值给节点
            if (value) {
                node.value = value;
            }
            else {
                node.value = "";
            }
        }
        if (layerInfo.META_DATA) {
            let metadata = JSON.parse(layerInfo.META_DATA);
            for (var j = 0; j < metaInfoNodes.length; j++) {
                node = metaInfoNodes[j];
                name = node.name;
                value = metadata[name];
                //将属性赋值给节点
                if (value) {
                    node.value = value;
                }
                else {
                    node.value = "";
                }
            }
        }
        if (lastLayerNode == layerNode || lastLayerNode == null) {
            changeNodeState(getNodeByID("div_field_info"));
        }
        else {
            changeNodeState(getNodeByID("div_field_info"), "", true);
        }
        isTransit = false;//非中转路径
        fillFieldInfoTable(layerguid);
        lastLayerNode = layerNode;
        getNodeByID("ipt_layer_guid").value = layerguid;
        $(".opraButton").css("display", "none");
    }
}
//获取资源目录对应地图服务资源
function getLayersByCatalog(orgID, catalogAttr) {
    var thisResult = "";
    var resourcetype = getResourceFilter(catalogAttr);
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Map/DataServer.ashx",
        data: //发送到服务器的参数
            {
                stype: "getLayersByCatalog",
                orgid: orgID,
                resourcetype: resourcetype
            },
        datatype: "json",
        success: function (result) {
            thisResult = result;
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
    thisResult = changeStrToJsonOrArray(thisResult, null, true, "json");
    return thisResult;
}
//获取图层组下图层列表
function getLayersByLayerGroup(layerGroupGuid) {
    var thisResult = "";
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Map/DataServer.ashx",
        data: //发送到服务器的参数
            {
                stype: "getLayersByLayerGroup",
                groupid: layerGroupGuid
            },
        datatype: "json",
        success: function (result) {
            thisResult = result;
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
    thisResult = changeStrToJsonOrArray(thisResult, null, true, "json");
    return thisResult;
}
//获取图层组下符合用户权限图层
function getLayersByGroupAndUser(groupName, columnName) {
    //var thisResult = null;
    //var sql = "select a.* from TB_Dataserver_Layer a left join TB_SERVER_MANGER b on a.guid=b.serverguid where " + columnName + "='true' and groupname='" + groupName + "' order by orderindex asc ";
    //var strData = GetDatatable(sql);
    //if (strData == "null" || strData=="") {
    //    thisResult = {};
    //}
    //else {
    //    thisResult = changeStrToJson(strData, "LAYERNAME", true);
    //}
    //return thisResult;
}
//获取资源类型条件
function getResourceFilter(catalogattr) {
    var catalogAttrArr = catalogattr.split("|");
    var resourcetype = null;
    var charasii, char;
    for (var i = 0; i < 5; i++) {
        charasii = 65 + i;
        char = asiiToStr(charasii);
        var resourceTypeValue;
        if (catalogAttrArr[i]) {
            resourceTypeValue = " like '%" + catalogAttrArr[i] + "%' ";
        }
        else {
            resourceTypeValue = " is null ";
        }
        if (i == 0) {
            resourcetype = "ATTR_" + char + resourceTypeValue;
        }
        else {
            resourcetype += " and ATTR_" + char + resourceTypeValue;
        }
    }
    return resourcetype;
}

//选择资源类型
function selectCatalog(isSwitch, node) {
    var catalogSelectNodes = getNodeByClass("select_resource_catalog");
    var selectNode, selectName, selectCatalogJson = {};
    for (var i = 0; i < catalogSelectNodes.length; i++) {
        selectNode = catalogSelectNodes[i];
        selectName = selectNode.attributes.name.value;
        selectCatalogJson[selectName] = selectNode.value;
    }
    if (selectCatalogJson["ATTR_A"] != "null") {
        getNodeByID("ipt_catalogattr").value = selectCatalogJson["ATTR_A"];
        if (selectCatalogJson["ATTR_B"] != "null") {
            getNodeByID("ipt_catalogattr").value += "|" + selectCatalogJson["ATTR_B"];
            if (selectCatalogJson["ATTR_C"] != "null") {
                getNodeByID("ipt_catalogattr").value += "|" + selectCatalogJson["ATTR_C"];
                if (selectCatalogJson["ATTR_D"] != "null") {
                    getNodeByID("ipt_catalogattr").value += "|" + selectCatalogJson["ATTR_D"];
                }
            }
        }
    }
    else {
        alert("一级目录必选");
        return;
    }
    if (isSwitch) {
        var target = $(node).attr("target");
        if (target == "arcgis") {
            changeNodeState(getNodeByID("div_add_catalog_select"), true);
            changeNodeState(getNodeByID("div_add_arcgis_info"), null, true);
            $(".font_checked_catalogattr").empty();
            $(".font_checked_catalogattr").append(getNodeByID("ipt_catalogattr").value.replace(/\|/g, " >> "));
            checkUnique($("input[class*=ipt_arcgis_info_add][name=LAYERALIAS]")[0]);
            //getNodeByID("font_checked_catalogattr").innerHTML = getNodeByID("ipt_catalogattr").value.replace(/\|/g, " >> ");
        }
        else if (target == "layer" || target == "default") {
            changeNodeState(getNodeByID("div_add_catalog_select"), true);
            changeNodeState(getNodeByID("div_add_layer_info"), null, true);
            $(".font_checked_catalogattr").empty();
            $(".font_checked_catalogattr").append(getNodeByID("ipt_catalogattr").value.replace(/\|/g, " >> "));
            //getNodeByID("font_checked_catalogattr").innerHTML = getNodeByID("ipt_catalogattr").value.replace(/\|/g, " >> ");
            checkUnique($("input[class*=ipt_layer_info_add][name=LAYERALIAS]")[0]);
        }
        else if (target == "3dtile") {
            changeNodeState(getNodeByID("div_add_catalog_select"), true);
            changeNodeState(getNodeByID("div_add_3dtile_info"), null, true);
            $(".font_checked_catalogattr").empty();
            $(".font_checked_catalogattr").append(getNodeByID("ipt_catalogattr").value.replace(/\|/g, " >> "));
            //getNodeByID("font_checked_catalogattr").innerHTML = getNodeByID("ipt_catalogattr").value.replace(/\|/g, " >> ");
            checkUnique($("input[class*=ipt_3dtile_info_add][name=LAYERALIAS]")[0]);
        }
        else if (target == "terrain") {
            changeNodeState(getNodeByID("div_add_catalog_select"), true);
            changeNodeState(getNodeByID("div_add_terrain_info"), null, true);
            $(".font_checked_catalogattr").empty();
            $(".font_checked_catalogattr").append(getNodeByID("ipt_catalogattr").value.replace(/\|/g, " >> "));
            //getNodeByID("font_checked_catalogattr").innerHTML = getNodeByID("ipt_catalogattr").value.replace(/\|/g, " >> ");
            checkUnique($("input[class*=ipt_terrain_info_add][name=LAYERALIAS]")[0]);
        }
    } 
}
//填充下级资源类型
function fillNextCatalog(node,catalogLevel) {
    var selectNodeNextName = "ATTR_A";
    var catalogid;
    if (catalogLevel) {
        if (catalogLevel == 1) {
            fillCatalogSelectOption("ATTR_B", {});
            fillCatalogSelectOption("ATTR_C", {});
            fillCatalogSelectOption("ATTR_D", {});
            selectNodeNextName = "ATTR_B";
            catalogid = $("select[class*=select_resource_catalog][name*=ATTR_A]").find("option:selected").attr("catalogid");
        }
        else if (catalogLevel == 2) {
            fillCatalogSelectOption("ATTR_C", {});
            fillCatalogSelectOption("ATTR_D", {});
            selectNodeNextName = "ATTR_C";
            catalogid = $("select[class*=select_resource_catalog][name*=ATTR_B]").find("option:selected").attr("catalogid");
        }
        else if (catalogLevel == 3) {
            fillCatalogSelectOption("ATTR_D", {});
            selectNodeNextName = "ATTR_D";
            catalogid = $("select[class*=select_resource_catalog][name*=ATTR_C]").find("option:selected").attr("catalogid");
        }
    }
    selectCatalog();
    //var optionData = resourceCatalogTree;
    //var catalogattr = getNodeByID("ipt_catalogattr").value;
    //catalogattr = catalogattr.split("|");
    var optionData;
    for (var i = 0; i < catalogid.length / 3; i++) {
        if (i == 0) {
            optionData = resourceCatalogTree[catalogid.slice(0, 3)].lower;
        }
        else {
            optionData = optionData[catalogid.slice(0, 3 * (i + 1))].lower;
        }
    }
    if (JSON.stringify(optionData) != "{}") {
        fillCatalogSelectOption(selectNodeNextName, optionData);
    }
}
//填充资源类型下拉项
function fillCatalogSelectOption(selectName, optionData) {
    var str;
    $("select[class*=select_resource_catalog][name*=" + selectName + "]").empty();
    switch (selectName) {
        case "ATTR_A": str = "一";
            break;
        case "ATTR_B": str = "二";
            break;
        case "ATTR_C": str = "三";
            break;
        case "ATTR_D": str = "四";
            break;
    }
    if (str!="一") {
        $("select[class*=select_resource_catalog][name*=" + selectName + "]").append("<option value='null'>----请选择"+str+"级目录----</option>");
    }
    for (var key in optionData) {
        $("select[class*=select_resource_catalog][name*=" + selectName + "]").append("<option catalogid='"+key+"' value='" + optionData[key].name + "'>" + optionData[key].name + "</option>");
    }
}


//选择行政区划
function selectXZQH(isSwitch,node) {
    var catalogSelectNodes = getNodeByClass("select_xzqh_catalog");
    var selectNode, selectName, selectXZQHJson = {};
    for (var i = 0; i < catalogSelectNodes.length; i++) {
        selectNode = catalogSelectNodes[i];
        selectName = selectNode.attributes.name.value;
        if (selectNode.value=="null") {
            continue;
        }
        selectXZQHJson[selectName] = $(selectNode).find("option:selected").text();
    }
    if (selectXZQHJson["SHENG"]) {
        getNodeByID("ipt_XZQH").value = selectXZQHJson["SHENG"];
        if (selectXZQHJson["SHI"]) {
            getNodeByID("ipt_XZQH").value += "|"+selectXZQHJson["SHI"];
            if (selectXZQHJson["XIAN"] ) {
                getNodeByID("ipt_XZQH").value += "|" + selectXZQHJson["XIAN"];
            }
        }
    }
    else {
        alert("请选择省级行政区");
        return;
    }
    if (isSwitch) {
        //if (getNodeByID("ipt_XZQH").value.split("|").length<3) {
        //    alert("请选择详细的行政区划");
        //    return;
        //}
        var target = $(node).attr("target");
        if (target == "arcgis") {
            changeNodeState(getNodeByID("div_add_xzqh_select"), true);
            changeNodeState(getNodeByID("div_add_arcgis_info"), null, true);
            $(".font_checked_xzqh").empty();
            $(".font_checked_xzqh").append(getNodeByID("ipt_XZQH").value.replace(/\|/g, " >> "));
            //getNodeByID("font_checked_xzqh").innerHTML = getNodeByID("ipt_XZQH").value.replace(/\|/g, " >> ");
        }
        else if (target == "layer" || target == "default") {
            changeNodeState(getNodeByID("div_add_xzqh_select"), true);
            changeNodeState(getNodeByID("div_add_layer_info"), null, true);
            $(".font_checked_xzqh").empty();
            $(".font_checked_xzqh").append(getNodeByID("ipt_XZQH").value.replace(/\|/g, " >> "));
            //getNodeByID("font_checked_xzqh").innerHTML = getNodeByID("ipt_XZQH").value.replace(/\|/g, " >> ");
        }
        else if (target == "3dtile") {
            changeNodeState(getNodeByID("div_add_xzqh_select"), true);
            changeNodeState(getNodeByID("div_add_3dtile_info"), null, true);
            $(".font_checked_xzqh").empty();
            $(".font_checked_xzqh").append(getNodeByID("ipt_XZQH").value.replace(/\|/g, " >> "));
            //getNodeByID("font_checked_xzqh").innerHTML = getNodeByID("ipt_XZQH").value.replace(/\|/g, " >> ");
        }
        else if (target == "terrain") {
            changeNodeState(getNodeByID("div_add_xzqh_select"), true);
            changeNodeState(getNodeByID("div_add_terrain_info"), null, true);
            $(".font_checked_xzqh").empty();
            $(".font_checked_xzqh").append(getNodeByID("ipt_XZQH").value.replace(/\|/g, " >> "));
            //getNodeByID("font_checked_xzqh").innerHTML = getNodeByID("ipt_XZQH").value.replace(/\|/g, " >> ");
        }
    }
}
//填充下级行政区划
function fillNextXZQH(node,XZQHLevel) {
    var selectNodeNextName = "SHENG";
    if (XZQHLevel) {
        if (XZQHLevel == 1) {
            fillXZQHSelectOption("SHI", null);
            fillXZQHSelectOption("XIAN", null);
            selectNodeNextName = "SHI";
        }
        else if (XZQHLevel == 2) {
            fillXZQHSelectOption("XIAN", null);
            selectNodeNextName = "XIAN";
        }
    }
    getNodeByID("ipt_XZQHDM").value = node.value;
    selectXZQH();
    if (XZQHLevel<3) {
        fillXZQHSelectOption(selectNodeNextName, node.value);
    }
}
//填充行政区划下拉项
function fillXZQHSelectOption(selectName, XZQDM) {
    var XZQHData;
    if (XZQDM!=null) {
        XZQHData = getLowerXZQH(XZQDM);
    }
    else {
        XZQHData = {};
    }
    var str;
    switch (selectName) {
        case "SHENG": str = "省"; break;
        case "SHI": str = "市"; break;
        case "XIAN": str = "县"; break;
        case "XIANG": str = "乡"; break;
    }
    $("select[class*=select_xzqh_catalog][name*=" + selectName + "]").empty();
    $("select[class*=select_xzqh_catalog][name*=" + selectName + "]").append("<option value='null'>----请选择" + str + "级行政区----</option>");
    for (var key in XZQHData) {
        $("select[class*=select_xzqh_catalog][name*=" + selectName + "]").append("<option value='" + XZQHData[key].XZQDM + "'>" + XZQHData[key].XZQMC + "</option>");
    }
}


//资源图标预览
function viewIcon(className) {
    var iconFileSelectNode = $("input[class*='" + className + "'][name='ZYTB']");
    if (iconFileSelectNode.val() == "" || iconFileSelectNode.val() == null || iconFileSelectNode.val() == "undefined") {
        var fileUpload = getNodeByID("fileUpload");
        fileUpload.click();
    }
    else {
        //deleteUserImgFile("admin");
        iconFileName = iconFileSelectNode.val();
        if (false) {
            open("/BaseAshx/Img/Transit/admin/" + iconFileName);
        }
        else {
            open("/img/BasePlatform/resource/" + iconFileName);
        }
    }
}
//上传文件存入中转文件夹
$("#fileUpload").change(function () {
    var file = this.files[0];
    var form = new FormData();
    form.append("stype", "uploadImg"); //实际业务的其他请求参数
    form.append("file", file); //第一个参数是后台读取的请求key值
    form.append("userno", getUser());
    form.append("fileName", file.name);
    var xhr = new XMLHttpRequest();
    var action = "/BaseAshx/Img/Img.ashx"; //上传服务的接口地址
    xhr.open("POST", action);
    xhr.send(form); //发送表单数据
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
            if (xhr.responseText == "False") {
                $(".file_upload_layer_ZYTB").val("fuw.jpg");
                $(".file_upload_arcgis_ZYTB").val("fuw.jpg");
                isTransit = false;
                alert("文件格式错误");
            }
            else {
                $(".file_upload_layer_ZYTB").val(xhr.responseText);
                $(".file_upload_arcgis_ZYTB").val(xhr.responseText);
                isTransit = true;
            }
            //var resultObj = JSON.parse(xhr.responseText);//处理返回的数据......
        }
    };
    getNodeByID("fileUpload").value = null;
})
//删除用户图标中转文件夹
function deleteUserImgFile(userno) {
    var thisResult = false;
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Img/Img.ashx",
        data: //发送到服务器的参数
            {
                stype: "deleteImg",
                userno:userno
            },
        datatype: "json",
        success: function (result) {
            if (result=="True") {
                thisResult = true;
            }
            
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
    return thisResult;
}


//改变页面大小
function changeBodySize() {
    var oCatalogList = document.getElementById('div_left_control');
    var oDataCatalog = document.getElementById('div_right_control');
    var frmainHeight = 0;
    var frmainWidth = 0;
    if (window.self && self.innerWidth) {
        frmainWidth = self.innerWidth; //得到火狐，谷歌，欧朋窗口大小
        frmainHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        frmainWidth = document.documentElement.clientWidth; //得到ie6以上窗口大小
        frmainHeight = document.documentElement.clientHeight;
    } else {
        frmainWidth = document.body.clientWidth; //得到ie6以下窗口大小
        frmainHeight = document.body.clientHeight;
    }
    var catalogWidth = (frmainWidth - 400) * 0.99;
    var catalogHeight = (frmainHeight - 40) * 0.95;
    oDataCatalog.style.height = (catalogHeight).toFixed(0) + "px";
    oDataCatalog.style.width = catalogWidth.toFixed(0) + "px";

    oCatalogList.style.height = catalogHeight.toFixed(0) + "px";

    $("#div_left_content_control").height($("#div_left_control").height() - 30);
}
//缩进
function suojinNode(num) {
    var node = createNode("span");
    var str = "";
    for (var i = 0; i < num; i++) {
        str += "&nbsp";
    }
    node.innerHTML = str;
    return node;
}
//打开右侧图层组信息或图层信息表格
function OpenGroupOrLayerInfo(type) {
    var layerInfoNode = getNodeByID("div_layer_info");
    changeNodeState(layerInfoNode, true);
    if (type=="layer") {
        changeNodeState(layerInfoNode);
        fillLayerSelect("ipt_layer_select");
    }
    else if (type=="none") {

    }
}
//鼠标移动到列表行上时效果
function onMouseOverOrOutFieldTable(trNode, newColor, newBackColor) {
    if (trNode.nodeName == "TD") {
        trNode = trNode.parentNode;
    }
    trNode.style.color = newColor;
    trNode.style.backgroundColor = newBackColor;
}
//点击蒙版
function clickMengBan(isclose) {
    var node = getNodeByID("div_mengban");
    if (isclose) {
        changeNodeState(node, true);
    }
    else {
        changeNodeState(node);
    }
    var node1 = getNodeByID("div_tanchu_add");
    changeNodeState(node1, true);
    var node2 = getNodeByID("div_tanchukuang");
    changeNodeState(node2, true);
}
//打开弹出框
function openTanchuAdd() {
    var node = getNodeByID("div_mengban");
    changeNodeState(node);
    var node = getNodeByID("div_tanchu_add");
    changeNodeState(node);
}
//打开资源添加框 图层组or图层or字段or目录or行政区
function openAddDiv(type, fieldValue) {
    if (type == "layer") {
        openTanchuAdd();
        getNodeByID("ipt_layer_guid").value = "insert";
        changeNodeState(getNodeByID("div_add_xzqh_select"), true);//不显示
        changeNodeState(getNodeByID("div_add_catalog_select"), true);
        changeNodeState(getNodeByID("div_add_field_info"), true);
        changeNodeState(getNodeByID("div_add_layer_info"), null, true);//显示
        changeNodeState(getNodeByID("div_add_arcgis_info"), true);
        changeNodeState(getNodeByID("div_add_3dtile_info"), true);
        changeNodeState(getNodeByID("div_add_terrain_info"), true);
        fillLayerSelect("ipt_layer_add_select");
        $("#submit_resource_catalog").attr("target", "default");
        $("#submit_xzqh_catalog").attr("target", "default");
    }
    else if (type == "arcgis") {
            openTanchuAdd();
            getNodeByID("ipt_layer_guid").value = "insert";
            changeNodeState(getNodeByID("div_add_xzqh_select"), true);
            changeNodeState(getNodeByID("div_add_catalog_select"), true);
            changeNodeState(getNodeByID("div_add_field_info"), true);
            changeNodeState(getNodeByID("div_add_layer_info"), true);
            changeNodeState(getNodeByID("div_add_arcgis_info"), null, true);//显示div_add_arcgis_info
            changeNodeState(getNodeByID("div_add_3dtile_info"), true);
            fillLayerSelect("ipt_arcgis_add_select");
            $("#submit_resource_catalog").attr("target", "arcgis");
            $("#submit_xzqh_catalog").attr("target", "arcgis");
    }
    else if (type == "3dtile") {
        openTanchuAdd();
        getNodeByID("ipt_layer_guid").value = "insert";
        changeNodeState(getNodeByID("div_add_xzqh_select"), true);
        changeNodeState(getNodeByID("div_add_catalog_select"), true);
        changeNodeState(getNodeByID("div_add_field_info"), true);
        changeNodeState(getNodeByID("div_add_layer_info"), true);
        changeNodeState(getNodeByID("div_add_arcgis_info"), true);
        changeNodeState(getNodeByID("div_add_3dtile_info"),null, true);
        fillLayerSelect("ipt_3dtile_add_select");
        $("#submit_resource_catalog").attr("target", "3dtile");
        $("#submit_xzqh_catalog").attr("target", "3dtile");
    }
    else if (type == "terrain") {
        openTanchuAdd();
        getNodeByID("ipt_layer_guid").value = "insert";
        changeNodeState(getNodeByID("div_add_xzqh_select"), true);
        changeNodeState(getNodeByID("div_add_catalog_select"), true);
        changeNodeState(getNodeByID("div_add_field_info"), true);
        changeNodeState(getNodeByID("div_add_layer_info"), true);
        changeNodeState(getNodeByID("div_add_arcgis_info"), true);
        changeNodeState(getNodeByID("div_add_terrain_info"), null, true);
        fillLayerSelect("ipt_terrain_add_select");
        $("#submit_resource_catalog").attr("target", "terrain");
        $("#submit_xzqh_catalog").attr("target", "terrain");
    }
    else if (type == "field") {
        openTanchuAdd();
        clearInputInfoByClass("ipt_field_info");
        changeNodeState(getNodeByID("div_add_xzqh_select"), true);
        changeNodeState(getNodeByID("div_add_catalog_select"), true);
        changeNodeState(getNodeByID("div_add_field_info"), null, true);
        changeNodeState(getNodeByID("div_add_layer_info"), true);
        changeNodeState(getNodeByID("div_add_arcgis_info"), true);
        fillFieldSelect();
        getNodeByID("ipt_field_order").value = getOrderNum("field", " where LAYERGUID='" + fieldValue + "'");
    }
    else if (type == "catalog") {
        changeNodeState(getNodeByID("div_add_xzqh_select"), true);
        changeNodeState(getNodeByID("div_add_catalog_select"),null, true);//显示目录选择页
        changeNodeState(getNodeByID("div_add_field_info"), true);
        changeNodeState(getNodeByID("div_add_layer_info"), true);
        changeNodeState(getNodeByID("div_add_arcgis_info"), true);
        changeNodeState(getNodeByID("div_add_3dtile_info"), true);
        changeNodeState(getNodeByID("div_add_terrain_info"), true);
        if ($("select[class*=select_resource_catalog][name*=ATTR_A]").find("option").length==1) {
            fillCatalogSelectOption("ATTR_A", resourceCatalogTree);
            fillNextCatalog($("select[class*=select_resource_catalog][name*=ATTR_A]")[0], 1);
            //存储目录ID
            $("#ipt_catalogID").val($("select[class*=select_resource_catalog][name*=ATTR_A] option:selected").attr("catalogid"));
            //console.log($("select[class*=select_resource_catalog][name*=ATTR_A] option:selected").attr("catalogid"));
            $(".select_resource_catalog").change(function (evt) {
                $("#ipt_catalogID").val($(evt.currentTarget).find("option:selected").attr("catalogid"));
                //console.log($(evt.currentTarget).find("option:selected").attr("catalogid"));
            })
        }

    }
    else if (type == "xzqh") {
        changeNodeState(getNodeByID("div_add_xzqh_select"), null, true);//显示行政区选择页
        changeNodeState(getNodeByID("div_add_catalog_select"), true);//关闭其他页
        changeNodeState(getNodeByID("div_add_field_info"), true);
        changeNodeState(getNodeByID("div_add_layer_info"), true);
        changeNodeState(getNodeByID("div_add_arcgis_info"), true);
        changeNodeState(getNodeByID("div_add_3dtile_info"), true);
        changeNodeState(getNodeByID("div_add_terrain_info"), true);
        if ($("select[class*=select_xzqh_catalog][name*=SHENG]").find("option").length == 1) {
            fillXZQHSelectOption("SHENG", "");
            $("select[class*=select_xzqh_catalog][name*=SHENG]").val("46");//默认选中内蒙古自治区
            fillNextXZQH($("select[class*=select_xzqh_catalog][name*=SHENG]")[0], 1)
        }
    }
    //else {
    //    openTanchuAdd();
    //}
}
//填充图层字段下拉框
function fillLayerSelect(className) {
    var layerSelects = $("." + className);
    var oneSelect, oneSelectName, zdName, dataDict;
    for (var i = 0; i < layerSelects.length; i++) {
        oneSelect = layerSelects[i];
        oneSelectName = oneSelect.attributes.name.value;
        if (oneSelectName == "SPATIAL") {
            zdName = "spatial";
            dataDict = getDataDict(zdName);
        }else if (oneSelectName == "SERVICESTYPE") {
            dataDict = getDataDict("serviceType");
        }else {
            zdName = "layer" + upperOrLower(oneSelectName);
            dataDict = getDataDict(zdName);
        }
        fillSelectUseDict(dataDict, oneSelect);
        if (oneSelectName == "RESOURCEPOSITION") {
            var strPositionData = null;
            var oneDataDict;
            strPositionData = getSpecialDataDict("position");
            $(oneSelect).empty();
            for (var key in strPositionData) {
                oneDataDict = strPositionData[key];
                $(oneSelect).append("<option ip = '"+oneDataDict.ZDVALUE +"'  value='" + oneDataDict.ID + "' title='" + oneDataDict.ZDTITLE + "'>" + oneDataDict.ZDTITLE + "</option>");
            }
        }
    if (oneSelectName == "COMPANY") {
            var portaluserno = getUser();
            var strCompanyData = null;
            strCompanyData = getCompanyDataDict(portaluserno);
            $(oneSelect).empty();
            $(oneSelect).append("<option value='" + strCompanyData.FK_DEPT + "' title='" + strCompanyData.FK_DEPTTEXT + "'>" + strCompanyData.FK_DEPTTEXT + "</option>");
        }
    }
    if (className == "ipt_layer_add_select") {
        $("input[class*='ipt_layer_info_add'][name='YEAR']").val(new Date().getFullYear());
        $("input[class*='ipt_layer_info_add'][name='ZYTB']").val("fuw.jpg");
    }
    else if (className == "ipt_arcgis_add_select") {
        $("input[class*='ipt_arcgis_info_add'][name='YEAR']").val(new Date().getFullYear());//数据年份
        $("input[class*='ipt_arcgis_info_add'][name='ZYTB']").val("fuw.jpg");//资源图标
        $("select[class*='ipt_arcgis_info_add'][name='COMPANY']").val(getUserORG());//所属机构
        //$("select[class*='ipt_arcgis_info_add'][name='RESOURCEPOSITION']").val("192.168.100.229:6080");//默认服务器
        //var userORG = getUserORG();
        //console.log(userORG);
    }
    else if (className == "ipt_3dtile_add_select") {
        $("input[class*='ipt_3dtile_info_add'][name='YEAR']").val(new Date().getFullYear());
        $("input[class*='ipt_3dtile_info_add'][name='ZYTB']").val("fuw.jpg");
        $("select[class*='ipt_3dtile_info_add'][name='COMPANY']").val(getUserORG());//所属机构
    }
    else if (className == "ipt_terrain_add_select") {
        $("input[class*='ipt_terrain_info_add'][name='YEAR']").val(new Date().getFullYear());
        $("input[class*='ipt_terrain_info_add'][name='ZYTB']").val("fuw.jpg");
        $("select[class*='ipt_terrain_info_add'][name='COMPANY']").val(getUserORG());//所属机构
    }
}
//填充字段信息下拉框
function fillFieldSelect() {
    var fieldSelects = $(".ipt_field_add_select");
    var oneSelect, oneSelectName, zdName, dataDict;
    var isSameValue = false;
    for (var i = 0; i < fieldSelects.length; i++) {
        oneSelect = fieldSelects[i];
        oneSelectName = oneSelect.attributes.name.value;
        if (oneSelectName == "TYPE") {
            zdName = "fieldfieldtype";
            dataDict = getDataDict(zdName);
            fillSelectUseDict(dataDict, oneSelect, isSameValue);
        }
        else if (oneSelectName == "ISQUERY") {
            oneSelect.value = "true";
        }
    }
}
//填充字段信息
function fillFieldInfoTable(layerguid) {
    if (!layerguid) {
        layerguid = lastLayerNode.attributes.layerguid.value;
    }
    var fieldsData = getDataServer("field", null, " where LAYERGUID = '" + layerguid + "' ", "*");
    $(".tr_field_info").remove();
    var fieldsTableNode = getNodeByID("tab_field_info");
    var newTrNode = null;
    var orderNum = 1;
    var fieldInfo = null;
    for (var key in fieldsData) {
        fieldInfo = fieldsData[key];
        newTrNode = fieldsTableNode.insertRow(orderNum + 1);
        newTrNode.style.color = "white";
        newTrNode.onmouseover = function (evt) {
            onMouseOverOrOutFieldTable(evt.target.parentNode, "#001154", "#A6D3FF");
        };
        if (orderNum % 2 == 1) {
            newTrNode.style.backgroundColor = "#3A3E52";
            newTrNode.onmouseout = function (evt) {
                onMouseOverOrOutFieldTable(evt.target.parentNode, "white", "#3A3E52");
            };
        }
        else if (orderNum % 2 == 0) {
            newTrNode.style.backgroundColor = "#2D3041";
            newTrNode.onmouseout = function (evt) {
                onMouseOverOrOutFieldTable(evt.target.parentNode, "white", "#2D3041");
            };
        }
        newTrNode.className = "tr_field_info";
        newTrNode.innerHTML = "<td>" + orderNum + "</td>"
            + "<td>" + fieldInfo.FIELDNAME + "</td>"
            + "<td>" + fieldInfo.FIELDALIAS + "</td>"
            + "<td>" + fieldInfo.TYPE + "</td>"
            + "<td>" + fieldInfo.ISQUERY + "</td>"
            + "<td>" + fieldInfo.ORDERINDEX + "</td>"
            + "<td  class='opraButton'>" + "<a href='#' onclick=opraFieldInfo('update','" + fieldInfo.GUID + "')>编辑</a>" + "<a href='#' onclick=opraFieldInfo('delete','" + fieldInfo.GUID + "')>删除</a>" + "</td>";
        orderNum++;
    }
}
//填充字段英文名
function fillFieldEnglish(node) {
    $("input[class*='ipt_field_info'][name*='FIELDNAME']").val(pinyin.getCamelChars(node.value));
}

//操作字段信息  更新、添加、删除
function opraFieldInfo(type,fieldguid) {
    switch (type) {
        case "update":
            getNodeByID("ipt_field_guid").value = fieldguid;
            var fieldInfo = getDataServer("field", "GUID", " where GUID='" + fieldguid + "'", "*");
            for (var key in fieldInfo) {
                fieldInfo = fieldInfo[key];
                break;
            }
            openAddDiv("field", fieldInfo.LAYERGUID);
            var fieldInfoNodes = document.getElementsByClassName("ipt_field_info");
            var node = null;
            var name = null;
            var value = null;
            for (var i = 0; i < fieldInfoNodes.length; i++) {
                node = fieldInfoNodes[i];
                name = node.name;
                value = fieldInfo[name];
                if (value) {
                    node.value = value;
                }
                else {
                    node.value = "";
                }
            }
            break;
        case "insert":
            getNodeByID("ipt_field_guid").value = "insert";
            openAddDiv("field",lastLayerNode.attributes.layerguid.value);
            break;
        case "delete":
            getNodeByID("ipt_field_guid").value = fieldguid;
            if (confirm("确认删除该字段？")) {
                var result = deleteServerInfo("field", " where GUID = '" + fieldguid + "' ");
                if (result) {
                    getDataServer("field", "FIELDNAME", " where LAYERGUID='" + lastLayerNode.attributes.layerguid.value + "'", "*");
                    fillFieldInfoTable();
                }
            }
            break;
        default:
            alert("操作有误！");
            break;
    }
}
//保存字段信息
function saveFieldInfo() {
    $(".noticenode").remove();
    if (!checkInputRight("div_add_field_info")) {
        return;
    }
    if (!checkInputIsNull("ipt_field_info", [])) {
        return;
    }
    var fieldInfos = document.getElementsByClassName("ipt_field_info");
    var fieldInfoNode = null;
    var newFieldInfo = {};
    var fieldInfoNodeName = null;
    var saveType = "update";
    var fieldGuid=getNodeByID("ipt_field_guid").value;
    if (fieldGuid=="insert") {
        saveType = "insert";
    }
    for (var i = 0; i < fieldInfos.length; i++) {
        fieldInfoNode = fieldInfos[i];
        fieldInfoNodeName = fieldInfoNode.attributes.name.value;
        newFieldInfo[fieldInfoNodeName] = fieldInfoNode.value;
        fieldInfoNodeName = null;
    }
    var layerguid = lastLayerNode.attributes.layerGUID.value;
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Map/DataServer.ashx",
        data: //发送到服务器的参数
            {
                stype: "InsertFieldInfo",
                savetype:saveType,
                name: newFieldInfo.FIELDNAME,
                alias: newFieldInfo.FIELDALIAS,
                type: newFieldInfo.TYPE,
                isquery: newFieldInfo.ISQUERY,
                layerguid: layerguid,
                ordernum: newFieldInfo.ORDERINDEX,
                fieldguid: fieldGuid
            },
        datatype: "json",
        success: function (result) {
            if (result=="True") {
                alert("插入成功");
                clearInputInfoByClass("ipt_field_info");
                clickMengBan();
                getDataServer("field", "FIELDNAME", " where LAYERGUID='" + lastLayerNode.attributes.layerguid.value + "'", "*");
                fillFieldInfoTable();
            }
            else if (result=="False") {
                alert("插入失败");
            }
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
}
//表单项检查是否为空
function checkEditInputIsNull(classname, canNullNameArr) {
    var isSubmit = true;
    var inputNodes = $("." + classname);
    var oneInputNode;
    var isnull;
    for (var i = 0; i < inputNodes.length; i++) {
        oneInputNode = inputNodes[i];
        if (oneInputNode.value != "" && oneInputNode.value != null) {
            continue;
        }
        else {
            isnull = false;
            for (var j = 0; j < canNullNameArr.length; j++) {
                if (canNullNameArr[j] == oneInputNode.attributes.name.value) {
                    isnull = true;
                    break;
                }
            }
            if (isnull) {
                continue;
            }
            else {
                layui.layer.msg('必填项不能为空', { icon: 5 })
                isSubmit = false;
            }
        }
    }
    return isSubmit;
}
//保存图层信息
function saveLayerInfo(ipt_class, isEditService) {
    layerInfoID = null;
    if (ipt_class == "ipt_layer_info_add" || isEditService) {
        if (isEditService) {//编辑未审核过的服务
            layerInfoID = "div_layer_info";
        }
        else {//添加服务
            layerInfoID = "div_add_layer_info";
        }
    }
    else {//编辑审核通过的服务
        layerInfoID = "div_layer_info";
        if (!confirm("继续提交需要重新审核服务信息并授予权限，确认继续吗？")) {
            return;
        }
    }
    if (!checkInputRight(layerInfoID)) {
        return;
    }
    if (!checkEditInputIsNull(ipt_class, ["ID", "STYLE", "YEAR","ZYTB","PARAMETERS",
        "SERVICENAME", "SERVICEPROFILE", "TYPE", "SERVICEADDRESS", "SERVICEVERSION",
        "GEODETICDATUMCOORDINATE", "HEIGHTDATUM", "CENTRALMERIDIAN", "WESTLON", "NORTHLAT", "EASTLON",
        "SOUTHLAT", "DATARELEASEUNIT", "SERVICERELEASETIME", "CONTACTPHONENUMBER", "HEADOFUNIT", ])) {
        return;
    }
    var layerInfos = document.getElementsByClassName(ipt_class);
    var newLayerInfo = {};
    var layerInfoNode = null;
    var layerInfoNodeName = null;
    var layerguid=null;
    for (var i = 0; i < layerInfos.length; i++) {
        layerInfoNode = layerInfos[i];
        layerInfoNodeName = layerInfoNode.attributes.name.value;
        newLayerInfo[layerInfoNodeName] = layerInfoNode.value;
        layerInfoNodeName = null;
    }
    if (getNodeByID("ipt_layer_guid").value=="insert") {
        save_type = "insert";
        if (!getNodeByID("ipt_catalogattr").value) {
            openAddDiv("catalog");
            return;
        }
        if (!getNodeByID("ipt_XZQHDM").value) {
            openAddDiv("xzqh");
            return;
        }
        layerguid = getGUID();
        var catalogattr = getNodeByID("ipt_catalogattr").value;
        newLayerInfo["catalogattr"] = catalogattr;
        var XZQHDM = getNodeByID("ipt_XZQHDM").value;
        newLayerInfo["AREA"] = XZQHDM;
        var layerFilter = getResourceFilter(catalogattr);
        newLayerInfo["ORDERINDEX"] = getOrderNum("resource", " where " + layerFilter);
    }
    else {
        save_type = "update";
        layerguid = getNodeByID("ipt_layer_guid").value;
        newLayerInfo["catalogattr"] = "";
        newLayerInfo["AREA"] = "";
        newLayerInfo["ORDERINDEX"] = "0";
    }
    newLayerInfo["LAYERNAME"] = pinyin.getCamelChars(newLayerInfo.LAYERALIAS);
    newLayerInfo["USERNO"] = getUser();
    newLayerInfo["VALUEPOSITION"] = $("select." + ipt_class + "[name*=RESOURCEPOSITION] option:selected").text();
    newLayerInfo["VALUESERVERTYPE"] = $("select[class*=" + ipt_class + "][name*=SERVERTYPE] option:selected").attr("title");
    newLayerInfo["VALUESERVICETYPE"] = $("select[class*=" + ipt_class + "][name*=SERVICETYPE] option:selected").attr("title");
    newLayerInfo["VALUESOURCE"] = $("select[class*=" + ipt_class + "][name*=SOURCE] option:selected").attr("title");
    newLayerInfo["VALUESTATUS"] = $("select[class*=" + ipt_class + "][name*=STATUS] option:selected").attr("title");
    var metaData;
    metaData = {
        "SERVICEVERSION": newLayerInfo.SERVICEVERSION,
        "GEODETICDATUMCOORDINATE": newLayerInfo.GEODETICDATUMCOORDINATE,
        "HEIGHTDATUM": newLayerInfo.HEIGHTDATUM,
        "CENTRALMERIDIAN": newLayerInfo.CENTRALMERIDIAN,
        "WESTLON": newLayerInfo.WESTLON,
        "NORTHLAT": newLayerInfo.NORTHLAT,
        "EASTLON": newLayerInfo.EASTLON,
        "SOUTHLAT": newLayerInfo.SOUTHLAT,
        "DATARELEASEUNIT": newLayerInfo.DATARELEASEUNIT,
        "SERVICERELEASETIME": newLayerInfo.SERVICERELEASETIME,
        "CONTACTPHONENUMBER": newLayerInfo.CONTACTPHONENUMBER,
        "HEADOFUNIT": newLayerInfo.HEADOFUNIT
    };
    metaData = JSON.stringify(metaData);
    var configInfo = InitialParameter("/Config.json"); 
    let modelApi = getBaseplatformPort();
    $.ajax({
        type: "post",
        async: false,
        //url: "/BaseAshx/Map/DataServer.ashx",
        url: modelApi + "resource/updateLayerInfo",
        data: //发送到服务器的参数
            {
                guid: layerguid,
                layername: newLayerInfo.LAYERNAME,//图层名
                layeralias: newLayerInfo.LAYERALIAS,//图层名称别名
                company: newLayerInfo.COMPANY,//所属单位
                spatial: newLayerInfo.SPATIAL,//主题
                id: newLayerInfo.ID,//服务ID
                style: newLayerInfo.STYLE,//样式
                layerposition: newLayerInfo.POSITION,//定位信息
                prj: newLayerInfo.PRJ,//投影信息
                parameters: newLayerInfo.PARAMETERS,//服务图层名
                servertype: newLayerInfo.SERVERTYPE,//地图服务类型
                source: newLayerInfo.SOURCE,//图层源类型
                status: newLayerInfo.STATUS,//加载状态
                isquery: newLayerInfo.ISQUERY,//是否可查
                servicetype: newLayerInfo.SERVICETYPE,//地图服务类型
                year: newLayerInfo.YEAR,//数据年份
                zytb: newLayerInfo.ZYTB,//资源图标
                position: newLayerInfo.VALUEPOSITION,//提供方
                address: newLayerInfo.ADDRESS,//服务地址
                userno: newLayerInfo.USERNO,

                orderindex: newLayerInfo.ORDERINDEX,
                catalogattr: newLayerInfo.catalogattr,
                area: newLayerInfo.AREA,
                catalogid: newLayerInfo.catalogattr,
                serviceCategory: newLayerInfo.SERVICESTYPE,//服务种类
                metaData: typeof (metaData) == 'string' ? metaData : JSON.stringify(metaData)
            },
        datatype: "json",
        success: function (result) {
            let data1 = JSON.parse(result)
            var thisResult = data1.data;
            if (thisResult == "error") {
                //alert("操作有误!");
                layui.layer.msg('操作有误!', { icon: 5 })
                return;
            }
            if (thisResult == "True") {
                layui.layer.msg('保存成功',{icon:1})
                if (getNodeByID("ipt_layer_guid").value == "insert") {
                    clearInputInfoByClass("ipt_layer_info_add");
                    clearInputInfoByClass("ipt_layer_info");
                    clickMengBan(true);
                    clearPageRight();
                }
            }
            else if (thisResult == "False") {
                //alert("保存失败");
                layui.layer.msg('保存失败!', { icon: 5 })
            }
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
}

//保存倾斜模型数据
function save3dTileLayerInfo(ipt_class, isEditService) {
    $(".noticenode").remove();
    layerInfoID = null;
    if (ipt_class == "ipt_3dtile_info_add" || isEditService) {
        if (isEditService) {//编辑未审核过的服务
            layerInfoID = "div_layer_info";
        }
        else {//添加服务
            layerInfoID = "div_add_3dtile_info";
        }
    }
    else {//编辑审核通过的服务
        layerInfoID = "div_layer_info";
        if (!confirm("继续提交需要重新审核服务信息并授予权限，确认继续吗？")) {
            return;
        }
    }
    if (!checkInputRight(layerInfoID)) {
        return;
    }
    if (!checkInputIsNull(ipt_class, ["ID", "STYLE", "PARAMETERS"])) {
        return;
    }
    var layerInfos = document.getElementsByClassName(ipt_class);
    var newLayerInfo = {};
    var layerInfoNode = null;
    var layerInfoNodeName = null;
    var layerguid = null;
    for (var i = 0; i < layerInfos.length; i++) {
        layerInfoNode = layerInfos[i];
        layerInfoNodeName = layerInfoNode.attributes.name.value;
        newLayerInfo[layerInfoNodeName] = layerInfoNode.value;
        layerInfoNodeName = null;
    }
    if (getNodeByID("ipt_layer_guid").value == "insert") {
        save_type = "insert";
        if (!getNodeByID("ipt_catalogattr").value) {
            openAddDiv("catalog");
            return;
        }
        if (!getNodeByID("ipt_XZQHDM").value) {
            openAddDiv("xzqh");
            return;
        }
        layerguid = getGUID();
        var catalogattr = getNodeByID("ipt_catalogattr").value;
        newLayerInfo["catalogattr"] = catalogattr;
        var XZQHDM = getNodeByID("ipt_XZQHDM").value;
        newLayerInfo["AREA"] = XZQHDM;
        var layerFilter = getResourceFilter(catalogattr);
        newLayerInfo["ORDERINDEX"] = getOrderNum("resource", " where " + layerFilter);
    }
    else {
        save_type = "update";
        layerguid = getNodeByID("ipt_layer_guid").value;
        newLayerInfo["catalogattr"] = "";
        newLayerInfo["AREA"] = "";
        newLayerInfo["ORDERINDEX"] = "0";
    }
    newLayerInfo["LAYERNAME"] = pinyin.getCamelChars(newLayerInfo.LAYERALIAS);
    newLayerInfo["USERNO"] = getUser();
    newLayerInfo["VALUEPOSITION"] = $("select." + ipt_class + "[name*=RESOURCEPOSITION] option:selected").text();
    newLayerInfo["VALUESERVERTYPE"] = $("select[class*=" + ipt_class + "][name*=SERVERTYPE] option:selected").attr("title");
    newLayerInfo["VALUESERVICETYPE"] = $("select[class*=" + ipt_class + "][name*=SERVICETYPE] option:selected").attr("title");
    newLayerInfo["VALUESOURCE"] = $("select[class*=" + ipt_class + "][name*=SOURCE] option:selected").attr("title");
    newLayerInfo["VALUESTATUS"] = $("select[class*=" + ipt_class + "][name*=STATUS] option:selected").attr("title");

    //add by zhaowanfeng
    newLayerInfo["SERVICETYPE"] = "oblique";
    newLayerInfo["SOURCE"] = "";
    newLayerInfo["STATUS"] = "online";
    newLayerInfo["PARAMETERS"] = "";
    newLayerInfo["SERVERTYPE"] = "";


    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Map/DataServer.ashx",
        data: //发送到服务器的参数
        {
            stype: "SaveLayerInfo",
            savetype: save_type,
            guid: layerguid,

            name: newLayerInfo.LAYERNAME,
            alias: newLayerInfo.LAYERALIAS,
            company: newLayerInfo.COMPANY,
            spatial: newLayerInfo.SPATIAL,
            layerid: newLayerInfo.ID,
            style: newLayerInfo.STYLE,
            position: newLayerInfo.POSITION,
            prj: newLayerInfo.PRJ,
            parameters: newLayerInfo.PARAMETERS,
            servertype: newLayerInfo.SERVERTYPE,
            source: newLayerInfo.SOURCE,
            status: newLayerInfo.STATUS,
            isquery: newLayerInfo.ISQUERY,
            servicetype: newLayerInfo.SERVICETYPE,
            year: newLayerInfo.YEAR,
            zytb: newLayerInfo.ZYTB,
            resourceposition: newLayerInfo.VALUEPOSITION,
            address: newLayerInfo.ADDRESS,
            userno: newLayerInfo.USERNO,

            ordernum: newLayerInfo.ORDERINDEX,
            catalogattr: newLayerInfo.catalogattr,
            area: newLayerInfo.AREA,
            catalogid: newLayerInfo.catalogattr
        },
        datatype: "json",
        success: function (result) {
            if (result == "error") {
                alert("操作有误!");
                return;
            }
            if (result == "True") {
                alert("保存成功");
                if (getNodeByID("ipt_layer_guid").value == "insert") {
                    clearInputInfoByClass("ipt_layer_info_add");
                    clearInputInfoByClass("ipt_layer_info");
                    clickMengBan(true);
                    clearPageRight();
                }

            }
            else if (result == "False") {
                alert("保存失败");
            }
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
}

//保存地形数据
function saveTerrainLayerInfo(ipt_class, isEditService) {
    $(".noticenode").remove();
    layerInfoID = null;
    if (ipt_class == "ipt_terrain_info_add" || isEditService) {
        if (isEditService) {//编辑未审核过的服务
            layerInfoID = "div_layer_info";
        }
        else {//添加服务
            layerInfoID = "div_add_terrain_info";
        }
    }
    else {//编辑审核通过的服务
        layerInfoID = "div_layer_info";
        if (!confirm("继续提交需要重新审核服务信息并授予权限，确认继续吗？")) {
            return;
        }
    }
    if (!checkInputRight(layerInfoID)) {
        return;
    }
    if (!checkInputIsNull(ipt_class, ["ID", "STYLE", "PARAMETERS"])) {
        return;
    }
    var layerInfos = document.getElementsByClassName(ipt_class);
    var newLayerInfo = {};
    var layerInfoNode = null;
    var layerInfoNodeName = null;
    var layerguid = null;
    for (var i = 0; i < layerInfos.length; i++) {
        layerInfoNode = layerInfos[i];
        layerInfoNodeName = layerInfoNode.attributes.name.value;
        newLayerInfo[layerInfoNodeName] = layerInfoNode.value;
        layerInfoNodeName = null; 
    } 
    if (getNodeByID("ipt_layer_guid").value == "insert") {
        save_type = "insert";
        if (!getNodeByID("ipt_catalogattr").value) {
            openAddDiv("catalog");
            return;
        }
        if (!getNodeByID("ipt_XZQHDM").value) {
            openAddDiv("xzqh");
            return;
        }
        layerguid = getGUID();
        var catalogattr = getNodeByID("ipt_catalogattr").value;
        newLayerInfo["catalogattr"] = catalogattr;
        var XZQHDM = getNodeByID("ipt_XZQHDM").value;
        newLayerInfo["AREA"] = XZQHDM;
        var layerFilter = getResourceFilter(catalogattr);
        newLayerInfo["ORDERINDEX"] = getOrderNum("resource", " where " + layerFilter);
    }
    else {
        save_type = "update";
        layerguid = getNodeByID("ipt_layer_guid").value;
        newLayerInfo["catalogattr"] = "";
        newLayerInfo["AREA"] = "";
        newLayerInfo["ORDERINDEX"] = "0";
    }
    newLayerInfo["LAYERNAME"] = pinyin.getCamelChars(newLayerInfo.LAYERALIAS);
    newLayerInfo["USERNO"] = getUser();
    newLayerInfo["VALUEPOSITION"] = $("select." + ipt_class + "[name*=RESOURCEPOSITION] option:selected").text();
    newLayerInfo["VALUESERVERTYPE"] = $("select[class*=" + ipt_class + "][name*=SERVERTYPE] option:selected").attr("title");
    newLayerInfo["VALUESERVICETYPE"] = $("select[class*=" + ipt_class + "][name*=SERVICETYPE] option:selected").attr("title");
    newLayerInfo["VALUESOURCE"] = $("select[class*=" + ipt_class + "][name*=SOURCE] option:selected").attr("title");
    newLayerInfo["VALUESTATUS"] = $("select[class*=" + ipt_class + "][name*=STATUS] option:selected").attr("title");

    //add by zhaowanfeng
    newLayerInfo["SERVICETYPE"] = "terrain";
    newLayerInfo["SOURCE"] = "";
    newLayerInfo["STATUS"] = "online";
    newLayerInfo["PARAMETERS"] = "";
    newLayerInfo["SERVERTYPE"] = "";


    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Map/DataServer.ashx",
        data: //发送到服务器的参数
        {
            stype: "SaveLayerInfo",
            savetype: save_type,
            guid: layerguid,

            name: newLayerInfo.LAYERNAME,
            alias: newLayerInfo.LAYERALIAS,
            company: newLayerInfo.COMPANY,
            spatial: newLayerInfo.SPATIAL,
            layerid: newLayerInfo.ID,
            style: newLayerInfo.STYLE,
            position: newLayerInfo.POSITION,
            prj: newLayerInfo.PRJ,
            parameters: newLayerInfo.PARAMETERS,
            servertype: newLayerInfo.SERVERTYPE,
            source: newLayerInfo.SOURCE,
            status: newLayerInfo.STATUS,
            isquery: newLayerInfo.ISQUERY,
            servicetype: newLayerInfo.SERVICETYPE,
            year: newLayerInfo.YEAR,
            zytb: newLayerInfo.ZYTB,
            resourceposition: newLayerInfo.VALUEPOSITION,
            address: newLayerInfo.ADDRESS,
            userno: newLayerInfo.USERNO,

            ordernum: newLayerInfo.ORDERINDEX,
            catalogattr: newLayerInfo.catalogattr,
            area: newLayerInfo.AREA,
            catalogid: newLayerInfo.catalogattr
        },
        datatype: "json",
        success: function (result) {
            if (result == "error") {
                alert("操作有误!");
                return;
            }
            if (result == "True") {
                alert("保存成功");
                if (getNodeByID("ipt_layer_guid").value == "insert") {
                    clearInputInfoByClass("ipt_layer_info_add");
                    clearInputInfoByClass("ipt_layer_info");
                    clickMengBan(true);
                    clearPageRight();
                }

            }
            else if (result == "False") {
                alert("保存失败");
            }
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
}

//删除地图服务信息
function deleteServerInfo(dataType, strWhere) {
    var thisResult = false;
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Map/DataServer.ashx",
        data: //发送到服务器的参数
            {
                stype: "DeleteInfo",
                datatype: dataType,
                strwhere: strWhere
            },
        datatype: "json",
        success: function (result) {
            if (result == "True") {
                alert("删除成功");
                thisResult = true;
                //open("/OneMap/DataServer/dataserver.html", "_parent");
            }
            else if (result == "False") {
                alert("删除失败");
            }
            else {//(result == "error") 
                alert("操作有误！");
            }
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
    return thisResult;
}
//点击删除按钮后  删除字段 图层 图层组
function deleteServer(dataType) {
    if (dataType == "field") {

    }
    else if (dataType == "layer") {
        if (getNodeByID("ipt_layer_guid").value == "insert") {
            alert("删除功能当前不可用！");
        }
        else {
            if (confirm("确定删除该图层？")) {
                var result = deleteServerInfo("layer", " where GUID = '" + getNodeByID("ipt_layer_guid").value + "' ");
                if (result) {
                    fillResourceCatalog();
                    clearPageRight();
                }
            }
        }
    }
    //else if (dataType == "group") {
    //    if (getNodeByID("ipt_group_guid").value == "insert") {
    //        alert("删除功能当前不可用！");
    //    }
    //    else {
    //        if (confirm("确定删除该图层组？")) {
    //            var result = deleteServerInfo("group", " where GUID = '" + getNodeByID("ipt_group_guid").value + "' ");
    //            if (result) {
    //                //重新加载
    //                getDataServer("group", "GROUPNAME", "", "*");
    //                fillLayerCatalog_Group(GroupsData);
    //                $(".group_title").click(function (evt) {
    //                    clickGroup(evt.target);
    //                });
    //            }

    //        }
    //    }
    //}
    else {
        alert("操作有误！");
    }
}


//页面右侧清空
function clearPageRight() {
    changeNodeState(getNodeByID("div_layer_info"),true);
    changeNodeState(getNodeByID("div_field_info"), true);
    $("#span_layer_path1")[0].innerHTML="根目录";
}
//清空输入信息
function clearInputInfoByClass(classname) {
    var nodes = document.getElementsByClassName(classname);
    var node = null;
    for (var i = 0; i < nodes.length; i++) {
        node = nodes[i];
        node.value = "";
    }
}
//表单项检查是否为空
function checkInputIsNull(classname,canNullNameArr) {
    var isSubmit = true;
    var inputNodes = $("." + classname);
    var oneInputNode;
    var noticeNode="<font style='color:red;font-size:16px;' class='noticenode'>*</font>";
    var isnull;
    for (var i = 0; i < inputNodes.length; i++) {
        oneInputNode = inputNodes[i];
        if (oneInputNode.value != "" && oneInputNode.value != null) {
            continue;
        }
        else {
            isnull = false;
            for (var j = 0; j < canNullNameArr.length; j++) {
                if (canNullNameArr[j] == oneInputNode.attributes.name.value) {
                    isnull = true;
                    break;
                }
            }
            if (isnull) {
                continue;
            }
            else {
                $(oneInputNode).after(noticeNode);
                isSubmit = false;
            }
        }
    }
    return isSubmit;
}
//表单项正确性检查
function checkInputRight(nodeID) {
    var isSubmit = true;
    if ($("#" + nodeID).find(".error").length > 0) {
        alert("请先更正错误信息！");
        isSubmit = false;
    }
    return isSubmit;
}
//获取排序数
function getOrderNum(type, strWhere) {
    if (!strWhere) {
        strWhere = "";
    }
    var thisResult = null;
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Resource/ResourceAshx.ashx",
        data: {
            stype: "getOrderNum",
            ordertype: type,
            strwhere: strWhere
        },
        datatype: "json",
        success: function (result) {
            thisResult = result;
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
    if (isNaN(thisResult)) {
        thisResult = 1;
    }
    return thisResult;
}
//更新排序序号
function updateOrderNum(dataType,guid,newIndex) {
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Map/DataServer.ashx",
        data: //发送到服务器的参数
            {
                stype: "UpdateOrder",
                dataType: dataType,
                guid: guid,
                newIndex: newIndex
            },
        datatype: "json",
        success: function (result) {
            if (result == "error") {
                alert("操作有误!");
                return;
            }
            if (result=="True") {

            }
            else if (result=="False") {

            }
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
}
//唯一性检查
function checkUnique(node) {
    if (node.value=="") {
        if ($(node.parentNode).find(".checkflag").length > 0) {
            $(node.parentNode).find(".checkflag").remove();
        }
        return;
    }
    var thisResult;
    var nodeName = node.attributes.name.value;
    var strWhere = "";
    var hasData = false;
    switch (nodeName) {
        case "LAYERALIAS":
            catalogattr = getNodeByID("ipt_catalogattr").value;
            if (catalogattr) {
                strWhere = " where NAME='"+node.value+"' and " + getResourceFilter(catalogattr);
            }
            else {
                strWhere = " where NAME='" + node.value + "'";
            }
            if (getJsonLength(getDataServer("resource", null, strWhere, "*"))>0) {
                hasData = true;
            }
            break;
        case "FIELDALIAS":
            strWhere = " where FIELDALIAS = '" + node.value + "' and LAYERGUID='" + lastLayerNode.attributes.layerguid.value + "' ";
            if (getJsonLength(getDataServer("field", null, strWhere, "*")) > 0) {
                hasData = true;
            }
            break;
        default:
            return;
    }
    var errorNode = createNode("font");
    errorNode.className = "checkflag error";
    errorNode.innerHTML = "✘";
    errorNode.style = "color:red;font-size:18px;";

    var rightNode = createNode("font");
    rightNode.className = "checkflag right";
    rightNode.innerHTML = "✔";
    rightNode.style = "color:#00C500;font-size:18px;";
    if ($(node.parentNode).find(".checkflag").length>0) {
        $(node.parentNode).find(".checkflag").remove();
    }
    if (hasData) {
        $(node).after(errorNode);
    }
    else {
        $(node).after(rightNode);
    }
}
//从数据库读取数据服务数据
function getDataServer(dataType, name, strWhere, fields) {
    var thisResult = {};
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Map/DataServer.ashx",
        data: //发送到服务器的参数
            {
                stype: "GetDataServerTable",
                dataType: dataType,
                strwhere: strWhere,
                fields: fields
            },
        datatype: "json",
        success: function (result) {
            if (result == "error") {
                alert("操作有误");
            }
            else {
                if (result == "null") {
                    thisResult = {};
                }
                else {
                    thisResult = changeStrToJsonOrArray(result, name, true, "json");
                }
            }
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
    return thisResult;
}


//获取行政区划
function getLowerXZQH(XZQDM) {
    var thisResult = null;
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Map/DataServer.ashx",
        data: //发送到服务器的参数
            {
                stype: "getXZQHData",
                xzqdm: XZQDM
            },
        datatype: "json",
        success: function (result) {
            thisResult = result;
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
    thisResult = changeStrToJsonOrArray(thisResult, null, true, "json");
    return thisResult;
}
//获取资源目录树
function getResourceCatalog() {
    var thisresult;
    var configInfo = InitialParameter("/Config.json"); 
    let modelApi = configInfo["modelTree"].type + '://' + configInfo["modelTree"].value 
    $.ajax({
        type: "post",
        async: false,
        //url: "/BaseAshx/Resource/CatalogManage.ashx"
        url: modelApi + "/sw/tree/getResourceTree",
        data: //发送到服务器的参数
            {
                //mtype: "CatalogManage_GetTreeList"
            },
        datatype: "json",
        success: function (result) {
            thisresult = result;
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
    return thisresult;
    //var thisResult = null;
    //$.ajax({
    //    type: "post",
    //    async: false,
    //    url: "/BaseAshx/Resource/ResourceAshx.ashx",
    //    data: //发送到服务器的参数
    //        {
    //            stype: "getResourceTree"
    //        },
    //    datatype: "json",
    //    success: function (result) {
    //        thisResult = result;
    //    }
    //});
    //return thisResult;
}
//获取资源目录树结构数据
function getTreeCatalog(CatalogTreeData) {
    var thisResult = {};
    var oneCatalog, catalogid, catalogname;
    for (var i = 0; i < CatalogTreeData.length; i++) {
        oneCatalog = CatalogTreeData[i];
        catalogid = oneCatalog.ID;
        if (catalogid.length / 3 == 1) {
            thisResult[catalogid] = {
                name: oneCatalog.NAME,
                lower: {}
            }
        }
        else if (catalogid.length / 3 == 2) {
            thisResult[catalogid.slice(0, 3)].lower[catalogid] = {
                name: oneCatalog.NAME,
                lower: {}
            }
        }
        else if (catalogid.length / 3 == 3) {
            thisResult[catalogid.slice(0, 3)].lower[catalogid.slice(0, 6)].lower[catalogid] = {
                name: oneCatalog.NAME,
                lower: {}
            }
        }
        else if (catalogid.length / 3 == 4) {
            thisResult[catalogid.slice(0, 3)].lower[catalogid.slice(0, 6)].lower[catalogid.slice(0, 9)].lower[catalogid] = {
                name: oneCatalog.NAME,
                lower: {}
            }
        }
    }
    return thisResult;
    var thisResult = {};
    var attrArr = ["ATTR_A", "ATTR_B", "ATTR_C", "ATTR_D", "ATTR_E", "ATTR_F", "ATTR_G", "ATTR_H", "ATTR_I", "ATTR_J"];
    var attrone;
    var catalogone;
    for (var key in CatalogTreeData) {
        catalogone = CatalogTreeData[key];
        if (catalogone["ATTR_A"] != "") {
            if (!thisResult[catalogone["ATTR_A"]]) {
                thisResult[catalogone["ATTR_A"]] = {};
            }
            if (catalogone["ATTR_B"] != "") {
                if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]]) {
                    thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]] = {};
                }
                if (catalogone["ATTR_C"] != "") {
                    if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]]) {
                        thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]] = {};
                    }
                    if (catalogone["ATTR_D"] != "") {
                        if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]]) {
                            thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]] = {};
                        }
                        if (catalogone["ATTR_E"] != "") {
                            if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]]) {
                                thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]] = {};
                            }
                            if (catalogone["ATTR_F"] != "") {
                                if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]]) {
                                    thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]] = {};
                                }
                                if (catalogone["ATTR_G"] != "") {
                                    if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]]) {
                                        thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]] = {};
                                    }
                                    if (catalogone["ATTR_H"] != "") {
                                        if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]]) {
                                            thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]] = {};
                                        }
                                        if (catalogone["ATTR_I"] != "") {
                                            if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]][catalogone["ATTR_I"]]) {
                                                thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]][catalogone["ATTR_I"]] = {};
                                            }
                                            if (catalogone["ATTR_J"] != "") {
                                                if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]][catalogone["ATTR_I"]][catalogone["ATTR_J"]]) {
                                                    thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]][catalogone["ATTR_I"]][catalogone["ATTR_J"]] = {};
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return thisResult;
}


//获取服务坐标系
function getServerEPSG() {
    var position = $("select[class*=ipt_layer_info_add][name*=RESOURCEPOSITION] option:selected").attr("title");
    var address = $("input[class*=ipt_layer_info_add][name*=ADDRESS]").val();
    var servertype = $("select[class*=ipt_layer_info_add][name*=SERVERTYPE] option:selected").attr("title");
    if (position && address && servertype == "arcgis") {
        $.getJSON("http://" + position + address + "?f=pjson", function (data) {
            if (data.hasOwnProperty("error")) {
                return;
            }
            else if (data.hasOwnProperty("spatialReference")) {
                $("input[class*=ipt_layer_info_add][name*=PRJ]").val("EPSG:" + data.spatialReference.latestWkid);
            }
        });
    }
}
//从数据库读取数据
function GetDatatable(sql) {
    var thisResult = null;
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Map/DataServer.ashx",
        data: //发送到服务器的参数
            {
                stype: "GetDatatable",
                sql:sql
            },
        datatype: "json",
        success: function (result) {
            thisResult = result;
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
    return thisResult;
}



//唯一性读库
//function checkUniqueFromDB(tableName, columName, columValue) {
//    var thisResult = false;
//    $.ajax({
//        type: "post",
//        async: false,
//        url: "/BaseAshx/Resource/ResourceAshx.ashx",
//        data: //发送到服务器的参数
//            {
//                stype: "isHasData",
//                tablename: tableName,
//                columname: columName,
//                columvalue: columValue
//            },
//        datatype: "json",
//        success: function (result) {
//            if (result == "True") {
//                thisResult = true;
//            }
//        }
//    });
//    return thisResult;
//}
